﻿Imports DTO
Imports System.Data.OleDb
Public Class ThoiKhoaBieuDAO
    Inherits Connect

    ''' <summary>
    ''' Lấy danh sách tên lớp có trong CSDL
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function LayDSLop() As IList
        Dim ds As New ArrayList
        Dim cn As New OleDbConnection
        cn = Me.ConnectionData
        Dim sql As String = "select * from lophoc"
        Dim cmd As New OleDbCommand(sql, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader

        While dr.Read
            Dim dto As New ThoiKhoaBieuDTO
            dto.TenLop = dr("TenLopHoc")
            dto.MaLop = dr("MaLopHoc")
            ds.Add(dto)
        End While
        cn.Close()
        Return ds
    End Function

    ''' <summary>
    ''' Lấy danh sách tên lớp có trong CSDL
    ''' </summary>
    ''' <param name="dto">Mã khối</param>
    ''' <returns>Danh sách tên lớp theo khối</returns>
    ''' <remarks></remarks>
    Public Function LayDSLop(ByVal dto As ThoiKhoaBieuDTO) As IList
        Dim ds As New ArrayList
        Dim cn As New OleDbConnection
        cn = Me.ConnectionData
        Dim sql As String = "select * from lophoc where MaKhoi='" & dto.Khoi & "'"
        Dim cmd As New OleDbCommand(sql, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            Dim tkbdto As New ThoiKhoaBieuDTO
            tkbdto.TenLop = dr("TenLopHoc")
            tkbdto.MaLop = dr("MaLopHoc")
            ds.Add(tkbdto)
        End While
        Return ds
    End Function

    ''' <summary>
    ''' Lấy mã của một lớp
    ''' </summary>
    ''' <param name="dto">Tên của lớp cần lấy mã</param>
    ''' 
    Public Function LayMaLop(ByVal dto As ThoiKhoaBieuDTO) As String
        Dim cn As New OleDbConnection
        cn = Me.ConnectionData
        Dim sql As String
        sql = "select MaLopHoc from LopHoc where TenLopHoc='" & dto.TenLop & "'"
        Dim cmd As New OleDbCommand(sql, cn)
        Return cmd.ExecuteScalar.ToString
    End Function

    'Public Function LayTKBLop(ByVal dto As ThoiKhoaBieuDTO) As List(Of String)
    '    Dim ds As New List(Of String)
    '    Dim cn As New OleDbConnection
    '    cn = Me.ConnectionData
    '    Dim sql As String
    '    sql = "select "
    '    Return ds

    'End Function

End Class
